home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / source / music4c.sit / Music4C Folder / orchestras / HoweExample1.c next >
Text File  |  1990-09-09  |  2KB  |  110 lines

  1. /*
  2. * ⌐ Graeme Gerrard 1990
  3. * Faculty of Music, University of Melbourne
  4. * Parkville Victoria 3052 Australia.
  5. *
  6. * ARPANET: grae@murdu.ucs.unimelb.edu.au
  7. * telephone: (613) 344 4127, Fax: (613) 344 5346
  8. */
  9. #include    "Music4c.h"
  10. #include    <math.h>
  11. #include    "orch.h"
  12. #include    "ugens.h"
  13.  
  14. #define    EXAMPLE1    1
  15. #define    MAXINS        6
  16. #define    NParams        13
  17.  
  18. static    double    *a;
  19. static    int        i[MAXINS];
  20. static    long    sampno;
  21. extern    FILE    *ReportFile;
  22. static    long    base;
  23.  
  24.  
  25. /* Exponentially decaying waveform, from Howe, p232 */
  26.  
  27. void initl()
  28. {
  29.     register long    j;
  30.     a = (double *)NewPtr(MAXINS * NParams * sizeof(double));
  31.     for ( j = 0; j < MAXINS * NParams; j++ )
  32.         *(a+j) = 0.0;
  33. }
  34.  
  35.  
  36. void setup()
  37. {
  38. /*
  39. * p4 = amp
  40. * p5 = pitch (in 8ve.pc)
  41. * p6 = number of waveform function
  42. * p7 = location, as a number between 1 and 4
  43. *
  44. */
  45.     switch(instype) {
  46.         case EXAMPLE1:
  47.             base = (insno * NParams) - NParams;
  48.             *(a+base) = p[4];
  49.             *(a+base+1) = p[4] * 0.1;
  50.             expset((a+base), (a+base+1), 1.5);
  51.             linset(0.01, p[3], 0.01, (a+base+2));
  52.             *(a+base+10) = pitch(p[5]);
  53.             *(a+base+12) = p[7] / 4.0;
  54.             
  55.             i[insno-1] = (int)p[6];
  56.             
  57.             break;
  58.         default:
  59.             /*fprintf(stderr, "error in instrument type number, %d\n", instype);*/
  60.             ;
  61.     }
  62. }
  63.  
  64. void orch()
  65. {
  66.     register    double    sig;
  67.     switch(instype) {
  68.         case EXAMPLE1:
  69.             base = (insno * NParams) - NParams;
  70. /* these calls are to the functions themselves
  71.             sig = expon((a+base), (a+base+1));
  72.             sig = linens(sig, (a+base+2));
  73.             sig = oscili(sig, *(a+base+10), i[insno-1], (a+base+11));
  74.             mono(sig*30000.);
  75. */
  76.  
  77. /* these are macro calls -
  78.    they are replaced on compilation by the definitions in ugens.h.
  79.    Saves the time of setting up all the function calls.  Notice that
  80.    the phase itself is the argument to the oscils, not the address!
  81. */
  82.             Expon(sig, (a+base), (a+base+1));
  83.             Linens(sig, sig, (a+base+2));
  84.             Oscili(sig, sig, *(a+base+10), i[insno-1], *(a+base+11));
  85.             Mono(sig*30000);
  86. /*            Stereo(sig, 0.5);*/
  87. /*            Output(sig *0.15, sig *0.2, sig * 0.22, sig * 0.15);*/
  88.             break;
  89.         default:
  90.             fprintf(stderr, "error in instrument type number, %d\n", instype);
  91.     }
  92. }
  93. void ter()
  94. {
  95. /* This routine gets called at the END of each note
  96. *  (like setup gets called at the beginning) and can be 
  97. *  useful for any clean up/file closure/statistics/reporting
  98. *  type things that you might want to do.
  99. *  Otherwise it just returns.
  100. */
  101. }
  102.  
  103.  
  104. void final()
  105. {
  106. /* called at the end of the synth run.
  107. *  close any files etc. you haven't already closed here.
  108. */
  109. }
  110.